package juc.Lock.reentrantLock;

import java.util.concurrent.locks.ReentrantLock;

public class demo2 {
    private static int num=0;
    private static ReentrantLock firelock=new ReentrantLock(true);

    static class thread extends Thread {
        public thread(String name) {
            super(name);
        }

        @Override
        public void run() {
            for (int i = 0; i < 10; i++) {
                firelock.lock();
                try {
                    System.out.println(this.getName() + "获得锁");
                } finally {
                    firelock.unlock();
                }
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new thread("t1");
        Thread t2 = new thread("t2");
        Thread t3 = new thread("t3");

        t1.start();
        t2.start();
        t3.start();
        t1.join();
        t2.join();
        t3.join();

    }
}

